package com.ssmdemo.controller;

import com.github.pagehelper.PageInfo;
import com.ssmdemo.dto.R;
import com.ssmdemo.pojo.TUsers;
import com.ssmdemo.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 咕唧
 * @Date 2022/5/24 15:57
 * @Version 1.0
 */
@RestController
@RequestMapping("/users")
public class TUserController {
    private TUserService tUserService;

    @Autowired
    public void settUserService(TUserService tUserService) {
        this.tUserService = tUserService;
    }

    @GetMapping("/find/{id}")
    public R findById(@PathVariable Long id) {
        TUsers tUsers = tUserService.findById(id);
        return R.setOK(tUsers);
    }

    @PostMapping("/user")
    public R addUser(@RequestBody TUsers tUser) {
        tUserService.addUser(tUser);
        return R.setOK();
    }

    @PostMapping("/user/update")
    public R updateUser(@RequestBody TUsers tUser) {
        tUserService.updateUser(tUser);
        return R.setOK();
    }

    @GetMapping("/findAll")
    public R findAll(@RequestParam(defaultValue = "2") int pageSize, @RequestParam(defaultValue = "1") int pageNum) {
        PageInfo<TUsers> pageInfo = tUserService.findAll(pageSize, pageNum);
        return R.setOK(pageInfo);
    }
}
